package com.yuncool.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Auther XIE
 * @Date 2019/9/2 17:04
 * @Description TODO
 * @Version 1.0
 */
@Service
public class CommonService {
	@Autowired
	private StringRedisTemplate redisTemplate;

	/**
	 * 检查验证码的正确性
	 *
	 * @param loginId
	 * @param code
	 * @return
	 */
	public Boolean checkSmsCode(String loginId, String code) {
		String trueCode = redisTemplate.opsForValue().get(loginId);
		if (null == trueCode) {
			return false;
		}
		if (trueCode.equals(code)) {
			//删除
			redisTemplate.delete(loginId);
			return true;
		}
		return false;
	}
}
